﻿using Abp.Domain.Entities.Auditing;
using DHJ.Cost.CostBooking;
using DHJ.Cost.Workshops;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using JetBrains.Annotations;

namespace DHJ.Cost.CostAccounting
{
    /// <summary>
    /// 核算关系
    /// </summary>
    public class AllocRel : CreationAuditedEntity<Guid>
    {
        [UsedImplicitly]
        private AllocRel()
        {
        }

        public AllocRel(Guid actualCostId, string batchId, int quantity,
            Workshop workshop, decimal ratio)
        {
            ActualCostId = actualCostId;
            BatchId = batchId;
            Quantity = quantity;
            Workshop = workshop;
            Ratio = ratio;
        }

        [Required]
        public string BatchId { get; private set; }

        public int Quantity { get; private set; }

        public Workshop Workshop { get; private set; }

        public decimal Ratio { get; private set; }

        [Required]
        public Guid ActualCostId { get; private set; }

        [ForeignKey(nameof(ActualCostId))]
        public ActualCost ActualCost { get; set; }

        public decimal UnitCost => ActualCost.Detail.Amount * Ratio / Quantity;
    }
}